dir = File.dirname(__FILE__)

require dir+'/exception_wrapper.rb'
require dir+'/mock.rb'
require dir+'/singleton.rb'
 
module Magic

  # Finds module of class
  def self.module_of given_class
    module_names = given_class.to_s.split('::')
    module_names.pop
    parent_module = Module
    module_names.each do |name|
      parent_module = parent_module.const_get(name.to_sym)
    end
    parent_module
  end

  # Finds class according to its string name
  def self.to_const string
    raise "Class should be string. Was #{string.class}." unless string.is_a?(String)
    module_names = string.split('::')
    constant = Module
    module_names.each do |name|
      constant = constant.const_get(name.to_sym)
    end
    constant
  end

  # Makes a deep copy of object
  def self.deep_copy o
    Marshal::load(Marshal.dump(o))
  end

  def self.wrap message, exception
    ExceptionWrapper.new message, exception
  end
  
end